package org.gd.hellojson.jackson.wrapper;

/**
 * @author Gorhover
 * @version 1.0-SNAPSHOT
 * @since 2013-09-18 08:49
 */
class WrapperFW<T extends Body> {

    @SuppressWarnings("unchecked")
    public Object wrap(T body) {
        try {
            Class<? extends Body> clazz = body.getClass();
            if(clazz.isAnnotationPresent(WrappedBy.class)) {
                WrappedBy wrappedBy = clazz.getAnnotation(WrappedBy.class);
                Wrapper<T> wrapper = wrappedBy.value().newInstance();
                wrapper.setBody(body);
                return wrapper;
            }
            return body;
        } catch (IllegalAccessException | InstantiationException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}
